package com.lc.pianostudent.activity;

import android.graphics.Interpolator;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

import com.lc.pianostudent.BaseApplication;
import com.lc.pianostudent.R;
import com.lc.pianostudent.conn.PostLogin;
import com.lc.pianostudent.conn.PostUserMyLevel;
import com.lc.pianostudent.view.TickProgress;
import com.littlejie.circleprogress.CircleProgress;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2018/7/12.
 */

public class MyRankActivity extends BaseActivity{
    @BoundView(R.id.total_rank) private TextView total_rank;
    @BoundView(R.id.next_rank) private TextView next_rank;
    @BoundView(R.id.progress)
    private TickProgress tickProgress;
    @BoundView(R.id.now)
    private TextView now;
    @BoundView(R.id.my_rank_head) private CircleImageView my_rank_head;

    @BoundView(R.id.need)
    private TextView need;
    @BoundView(R.id.need_two)
    private TextView need_two;
    @BoundView(R.id.total_dengji) private TextView total_dengji;
    @BoundView(R.id.next_dengji) private TextView next_dengji;

    private CircleProgress mCircleProgress1;

    //我的等级
    private PostUserMyLevel postUserMyLevel = new PostUserMyLevel(new AsyCallBack<PostUserMyLevel.PostUserMyLevelInfo>() {

        @Override
        public void onSuccess(String toast, int type, Object o, PostUserMyLevel.PostUserMyLevelInfo postUserMyLevelInfo) throws Exception {
            total_rank.setText("Lv."+postUserMyLevelInfo.grade);
            next_rank.setText("Lv."+postUserMyLevelInfo.next);
            tickProgress.setProgress(Float.parseFloat(postUserMyLevelInfo.now) / (Float.parseFloat(postUserMyLevelInfo.now)+Float.parseFloat(postUserMyLevelInfo.need)));

            mCircleProgress1.setMaxValue((Integer.parseInt(postUserMyLevelInfo.now)+Integer.parseInt(postUserMyLevelInfo.need)));
            mCircleProgress1.setValue(Integer.parseInt(postUserMyLevelInfo.now));

            now.setText("我的经验值："+postUserMyLevelInfo.now);
            need.setText("离升级还差："+postUserMyLevelInfo.need);
            need_two.setText(postUserMyLevelInfo.need);

            GlideLoader.getInstance().get(MyRankActivity.this,BaseApplication.BasePreferences.readHeadImg(),my_rank_head);
            total_dengji.setText("Lv."+postUserMyLevelInfo.grade);
            next_dengji.setText("Lv."+postUserMyLevelInfo.next);
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_rank);

        setBackTrue();

        initView();
    }

    private void initView(){
        setTitleName("我的等级");
        mCircleProgress1 = (CircleProgress) findViewById(R.id.circle_progress_bar1);
        total_rank.setTypeface(Typeface.createFromAsset(context.getAssets(), "font/ziti.TTF"));
        next_rank.setTypeface(Typeface.createFromAsset(context.getAssets(), "font/ziti.TTF"));

        postUserMyLevel.user_id = BaseApplication.BasePreferences.readUID();
        postUserMyLevel.execute();


    }


}
